<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<script language="javascript" src="${basePath }commonJs/tags/My97DatePicker/WdatePicker.js"></script>
<script language="javascript" src="${basePath }commonJs/system/update_pwd.js"></script>
<script type="text/javascript">
	var result = true;
	var status = "${detailLeave.status}";
	$(document).ready(function() {
		$("#leaveList_class").addClass("content_hover");
		 $("#leaveType").empty();
		 loadLeaveType();
		 $("#lveStartHM").val("${detailLeave.lveStartHM}");
		 $("#lveEndHM").val("${detailLeave.lveEndHM}");
		$("#btnSave").click(function() {
			$("#btnType").val("1"); //保存
			result =valiForm();
			if(result){
				$.messager.confirm('提示', '确认要保存吗?', function(r) {
					if (r) {
						result = false;
						$("#form1").submit();
					}
				});
			}
		});
		$("#btnSubmit").click(function() {
			result =valiForm();
			if(result){
				$.messager.confirm('提示', '确认要开始请假流程吗?', function(r) {
					if (r) {
						$("#btnType").val("2");//提交
						result = false;
						$("#form1").submit();
					}
				});
			}
		});
		$("#btnComplete").click(function() {//提交
			if(result){
				$.messager.confirm('提示', '确认要提交吗?', function(r) {
					if (r) {
						$("#handleResult").val("1"); 
						 result = false;
						$("#form2").submit();
					}
				});
			}
		});
		$("#btnBack").click(function() { //退单
			if(result){
				$.messager.confirm('提示', '确认要退回吗?', function(r) {
					if (r) {
						$("#handleResult").val("2"); 
						result = false;
						$("#form2").submit();
					}
				});
			}
		});
		$("#reApply").click(function() {
			result = valiForm();
			if(result){
				$.messager.confirm('提示', '确认要重新申请吗?', function(r) {
					if (r) {
						$("#btnType").val("3"); //重新申请
						result = false;
						$("#form1").submit();
					}
				});
			}
		});
		$("#endProcess").click(function() {
			$.messager.confirm('提示', '确认要关闭流程吗?', function(r) {
				if (r) {
					$("#btnType").val("4"); //结束流程
					if(result){
						result = false;
						$("#form1").submit();
					}
				}
			});
		});
	});
	
	function valiForm(){
		var reason = $("#lveReason").val();
		if($("#applyBy").val() == ''){
			alertError("请求已超时,请重新登录");
			return false;
		}
		if($("#lveStart").val() == ''){
			alertError("开始时间不能为空");
			return false;
		} 
		if($("#lveEnd").val() == ''){
			alertError("结束时间不能为空");
			return false;
		}
		if($("#lveReason").val() == ''){
			alertError("请假原因不能为空");
			return false;
		}else{
			if(reason.length > 300){
				alertError("请假原因不能超过300个字符");
				return false;
			}
		}
		if($("#lveEndYMD").val() == $("#lveStartYMD").val() && $("#lveEndHM").val() == $("#lveStartHM").val()){
			alertError("开始和结束时间不能相同");
			return false;
		}
		return true;
	}
	
	//页面进入就加载请假类型列表
	function loadLeaveType(){
		$.ajax({  
            type: "get",  
            url: "${basePath }workflow/leave/findLeaveTypeList.shtml",  
            cache: false,
	        async: false,
	        dataType: 'json',  
            data: {},  //没参数可以删除
            success: function (data) { 
            	$(data).each(function(n){
            			if(this.key == "${detailLeave.leaveTypeId }")
    						$("#leaveType").append("<option value='"+this.key+"' selected>"+this.value+"</option>");
            			else
            				$("#leaveType").append("<option value='"+this.key+"'>"+this.value+"</option>");
    		    });   
            	refreshSelect();
            } ,
            error : function(XMLHttpRequest) {
				ajaxError(XMLHttpRequest);
			}
        });  
	}
</script>
<title>嘉童游乐中心</title>
</head>
<body class="bg">
<div class="content m_auto">
	<%@include file="../indexPage/index_tab.jsp"%>
    
    
    <div class="content_r mt10">
    	<br />
    	<form action="${basePath }workflow/leave/updateLeave.shtml?pkLeaveId=${detailLeave.pkLeaveId}" id="form1" name="form1" method="post">
        <input type="hidden" name="fkFlowinstId" value="${detailLeave.processInstanceId }"/> 
        <input type="hidden" id ="btnType" name ="btnType"/>
        <div class="file_apply_l fixed mt50 border_r">
        
        <dl class="order_add_l_dl">
            <dd><label>申请编号：</label><input type="text"  class="iput_t w200"  id="pkLeaveId" name="pkLeaveId" value="${detailLeave.pkLeaveId }" disabled="disabled" /></dd>
            <dd><label>申请人：</label><input type="text" class="iput_t w200" value="${detailLeave.applyName }" disabled="disabled" /></dd>
            <c:choose>
                	<c:when test="${(detailLeave.status == '2' && detailLeave.workflowVo.isCurrtOpt == '1' && detailLeave.workflowVo.isStartUser == '1') || detailLeave.status == '1'}">
                			<dd><label>请假类型：</label>
                			<div class="uboxstyle">
                			<select name="pkLvetypeId" id="leaveType">
                    		</select>
                			</div>
            				</dd>
            				 <dd><label>请假开始时间：</label><input title="" type="text" name="lveStartYMD" id="lveStartYMD" value="${detailLeave. lveStartYMD}"
					onclick="WdatePicker({dateFmt:'yyyy/MM/dd',minDate:'%y/%M/%d',maxDate:'#F{$dp.$D(\'lveEndYMD\')}',isShowWeek:true,isShowClear:true,readOnly:true})"
					class="Wdate iput_t w82" readonly="readonly" />
					<div class="uboxstyle_small">
					<select name="lveStartHM" id="lveStartHM" >
						<option value="09:00" selected="selected">09:00</option>
						<option value="09:30">09:30</option>
						<option value="10:00">10:00</option>
						<option value="10:30">10:30</option>
						<option value="11:00">11:00</option>
						<option value="11:30">11:30</option>
						<option value="12:00">12:00</option>
						<option value="12:30">12:30</option>
						<option value="13:00">13:00</option>
						<option value="13:30">13:30</option>
						<option value="14:00">14:00</option>
						<option value="14:30">14:30</option>
						<option value="15:00">15:00</option>
						<option value="15:30">15:30</option>
						<option value="16:00">16:00</option>
						<option value="16:30">16:30</option>
						<option value="17:00">17:00</option>
						<option value="17:30">17:30</option>
						<option value="18:00">18:00</option>
						<option value="18:30">18:30</option>
						<option value="19:00">19:00</option>
						<option value="19:30">19:30</option>
						<option value="20:00">20:00</option>
						<option value="20:30">20:30</option>
						<option value="21:00">21:00</option>
						<option value="21:30">21:30</option>
						<option value="22:00">22:00</option>
						<option value="22:30">22:30</option>
					</select></div></dd>
            		<dd><label>请假结束时间：</label><input title="" type="text" name="lveEndYMD" id="lveEndYMD" value="${detailLeave. lveEndYMD}"
					onclick="WdatePicker({dateFmt:'yyyy/MM/dd',minDate:'#F{$dp.$D(\'lveStartYMD\')}',isShowWeek:true,isShowClear:true,readOnly:true})"
					class="Wdate iput_t w82" readonly="readonly" />
					<div class="uboxstyle_small">
					<select name="lveEndHM" id="lveEndHM">
						<option value="09:00" selected="selected">09:00</option>
						<option value="09:30">09:30</option>
						<option value="10:00">10:00</option>
						<option value="10:30">10:30</option>
						<option value="11:00">11:00</option>
						<option value="11:30">11:30</option>
						<option value="12:00">12:00</option>
						<option value="12:30">12:30</option>
						<option value="13:00">13:00</option>
						<option value="13:30">13:30</option>
						<option value="14:00">14:00</option>
						<option value="14:30">14:30</option>
						<option value="15:00">15:00</option>
						<option value="15:30">15:30</option>
						<option value="16:00">16:00</option>
						<option value="16:30">16:30</option>
						<option value="17:00">17:00</option>
						<option value="17:30">17:30</option>
						<option value="18:00">18:00</option>
						<option value="18:30">18:30</option>
						<option value="19:00">19:00</option>
						<option value="19:30">19:30</option>
						<option value="20:00">20:00</option>
						<option value="20:30">20:30</option>
						<option value="21:00">21:00</option>
						<option value="21:30">21:30</option>
						<option value="22:00">22:00</option>
						<option value="22:30">22:30</option>
					</select></div></dd>
            <dd><label>请假原因：</label><textarea style="width:210px" rows="10" name="lveReason" id="lveReason">${detailLeave.reason }</textarea></dd>
                	</c:when>
                	<c:otherwise>
                			<dd><label>请假类型：</label><input type="text" class="iput_t w200" value="${detailLeave.leaveType }" disabled="disabled" /></dd>
                			<dd><label>请假开始时间：</label><input type="text" class="iput_t w200" value="${detailLeave.startTime }" disabled="disabled"/></dd>
                			<dd><label>请假结束时间：</label><input type="text" class="iput_t w200" value="${detailLeave.endTime }" disabled="disabled"/></dd>
                			<dd><label>请假原因：</label><textarea style="width:210px" rows="10" disabled="disabled">${detailLeave.reason }</textarea></dd>
                	</c:otherwise>
            </c:choose>
            
            
        </dl>
        </div>
        </form>
        <div class="file_apply_r f14 p20 mt30">
            <div class="fl w600">
            	<div id="case2" class="fl w600">
								<dl class="order_add_l_dl">
									<dd>
										<label><b>当前状态：</b></label> ${detailLeave.workflowVo.statusDesc}
									</dd>
									<c:if test="${detailLeave.status != '1'}">
										<dd>
										<label><b>处理历史：</b></label>  </dd>
										<dd style="margin-left: 50px;">
											<table class="table">
												<tr>
													<th>时间</th>
													<th>处理人</th>
													<th>结果</th>
													<th>意见</th>
												</tr>
												<c:forEach items="${detailLeave.workflowVo.optHisVoList }" var="his">
													<tr>
														<td style="width: 40%">${his.optTime }</td>
														<td>${his.optName }</td>
														<td>${his.result }</td>
														<td title="${his.advice}">
														<c:if test="${his.advice != null}">
															<c:choose>
																<c:when test="${his.advice.length() > 5}">
																	${his.advice.substring(0,5)}...
																</c:when>
																<c:otherwise>
																	${his.advice}
																</c:otherwise>
															</c:choose>
														</c:if>
														</td>
													</tr>
												</c:forEach>
											</table>
										</dd>
										<c:if test="${detailLeave.status == '2' && detailLeave.workflowVo.isStartUser != '1' && detailLeave.workflowVo.isCurrtOpt == '1'}">
											<form action="${basePath }workflow/leave/complete.shtml" method="post" id="form2" name="form2">
														<input type="hidden" id="handleResult" name="handleResult" />
														<input type="hidden" name="businessKey" value="${detailLeave.pkLeaveId }" />
														<input type="hidden" name="processInstanceId" value="${detailLeave.processInstanceId }"/> 
													<dd><label>审批结果：</label> <input type="radio" name="handleAdvice" value="1" checked style="width: 20px" />同意 
																				<input type="radio" name="handleAdvice" value="0" style="width: 20px" />不同意
													</dd>
													<dd><label>审批意见：</label>
														<textarea rows="10" class="textare w300" name="handleReason"></textarea>
													</dd>
											</form>
										</c:if>
									</c:if>
									</dl>
									 <div class="btm_btn">
                        							<dl>
											<c:choose>
											<c:when test="${detailLeave.status == '2' &&  detailLeave.workflowVo.isCurrtOpt == '1'}">
												<c:choose>
												<c:when test="${ detailLeave.workflowVo.isStartUser == '1' && detailLeave.workflowVo.isCurrtOpt == '1'}">
													<dd><input type="button" class="btn" onclick="javascript:history.go(-1);" value="返回" /></dd>
                            						<dd><input type="button" class="btn" id="reApply" value="提交" /></dd>
												</c:when>
												<c:otherwise>
													<dd><input type="button" class="btn" onclick="javascript:history.go(-1);" value="返回" /></dd>
													<dd><input type="button" class="btn" id="btnBack" value="退单" /></dd>
													<dd><input type="button" class="btn" id="btnComplete" value="提交" /></dd>
												</c:otherwise>
												</c:choose>
												<dd><input type="button" class="btn" id="endProcess" value="关闭" /></dd>
											</c:when>
											<c:otherwise>
												<c:choose>
												<c:when test="${detailLeave.status == '1'}">
													  	<dd><input type="button" class="btn" onclick="javascript:history.go(-1);" value="返回" /></dd>
                           		 						<dd><input type="button" class="btn" id="btnSave" value="保存" /></dd>
                            							<dd><input type="button" class="btn" id="btnSubmit" value="提交" /></dd>
												</c:when>
												<c:otherwise>
													<input type="button" class="btn" onclick="javascript:history.go(-1);" value="返回" />
												</c:otherwise>
												</c:choose>
											</c:otherwise>
										</c:choose>
										</dl>
										</div>
						</div>
            </div>
        </div>
       
    </div>
</div>
</body>
</html>